import axios from './axios';

export const fetchLayout = async (plHangNo: string) => {
  console.log(plHangNo);
  return axios.post('/threeDimensions/getLayoutJson', { plHangNo });
};

export const updateLayout = async (
  plHangNo: string,
  modelDataJson: string,
  modelFileList: IModel[],
  hangsList: IHang[]
) => {
  return axios.post('/threeDimensions/modelEdit', {
    plHangNo,
    modelDataJson,
    modelFileList,
    hangsList,
  });
};

export interface IModel {
  id: string;
  total: number;
  applyNum: number;
}

interface IHang {
  total: number;
  hangType: number;
}

interface IMsg {
  plHangNo: string;
  partList: string[];
  messageType: number;
}

export const sendMsg = (data: IMsg) => {
  return axios.post('/sendMsg', data);
};

export const getPanel = async (plHangNo: string) => {
  return axios.post('/threeDimensions/query/hangGroupInfo', { plHangNo });
};

export const exportLayout = (plHangNo: string, file: File) => {
  const formData = new FormData();
  formData.append('file', file);
  formData.append('plHangNo', plHangNo);
  return axios.post('/threeDimensions/export/model', formData);
};
